package com.sinog.front.controller.biz;

import com.sinog.core.util.ConvertHttpToMap;
import com.sinog.front.feign.biz.SearchCodeList;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * @desc 行政区划查询(需要合并到tbsys_code查询)
 * @author -
 * @date -
 */
@RestController
public class SearchCodeReviewController {

    @Resource
    private SearchCodeList searchCodeList;

    /**
     * 犯罪类型code码查询
     * @param request request
     * @return List<Map<String,String>>
     */
    @RequestMapping("/yazgl/xjxx/fzlx/code")
    public List<Map<String,String>> toSearchCodeList(HttpServletRequest request) {
        Map<String,Object> searchMap = ConvertHttpToMap.getParameterMap(request);
        String codeType = (String)searchMap.get("codeType");
        return searchCodeList.getCodeList(codeType);
    }

    /**
     * 行政区划代码查询
     * @param request request
     * @return List<Map<String,String>>
     */
    @RequestMapping("/search/code/native")
    public List<Map<String,String>> toSearchCodeNativeList(HttpServletRequest request) {
        Map<String,Object> searchMap = ConvertHttpToMap.getParameterMap(request);
        String codeType = (String)searchMap.get("codeType");
        String pcodeId = (String)searchMap.get("pcodeId");
        boolean go = (StringUtils.isEmpty(pcodeId)) || (StringUtils.isEmpty(codeType));
        return go ? null : searchCodeList.getCodeNativeList(codeType,pcodeId);
    }

    /**
     * 街道代码查询
     * @param request request
     * @return List<Map<String,String>>
     */
    @RequestMapping("/search/code/jiedao")
    public List<Map<String,String>> toSearchCodeJieDaoList(HttpServletRequest request) {
        Map<String,Object> searchMap = ConvertHttpToMap.getParameterMap(request);
        String pcodeId = (String)searchMap.get("pcodeId");
        boolean go = StringUtils.isEmpty(pcodeId);
        return go ? null : searchCodeList.getCodeJieDaoList(pcodeId);
    }

    /**
     * 根据codeid与codetype
     * 查询 tbsys_code 表
     * @param request request
     * @return List<Map<String,String>>
     */
    @RequestMapping("/search/code/bycodeid")
    public List<Map<String,String>> toSearchByCodeId(HttpServletRequest request) {
        Map<String,Object> searchMap = ConvertHttpToMap.getParameterMap(request);
        String codeType = (String)searchMap.get("codeType");
        String codeId = (String)searchMap.get("codeid");
        return searchCodeList.getCodeByCodeId(codeType,codeId);
    }
}